package Demo3;

public class Complex {
    private int realpart;
    private int imaginpart;
    public int getRealpart(int realpart){
        return realpart;
    }
    public void setRealpart(int realpart){
        this.realpart=realpart;
    }
    public int getImaginpart(int imaginpart){
        return imaginpart;
    }
    public void setImaginpart(int imaginpart){
        this.imaginpart=imaginpart;
    }
    public Complex plus(Complex c){
        int real=this.realpart+c.realpart;
        int imagin=this.imaginpart+c.imaginpart;
        Complex result=new Complex();
        result.realpart=real;
        result.imaginpart=imagin;
        return result;
    }
    public Complex minus(Complex c){
        int real=this.realpart-c.realpart;
        int imagin=this.imaginpart-c.imaginpart;
        Complex result=new Complex();
        result.realpart=real;
        result.imaginpart=imagin;
        return result;
    }
    public String format(){
        if(this.imaginpart<0){
            return this.realpart+"+"+"("+this.imaginpart+"i"+")";
        }else{
            return this.realpart+"+"+this.imaginpart+"i";
        }
    }
}
